from typing import List
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from mooc.api import deps
from mooc.crud.crud_account import account_baiduapp
from mooc.schemas.account import AccountBaiduappCreate, AccountBaiduappRead, AccountBaiduappUpdate

account_router = APIRouter()

@account_router.post("/baiduapp", response_model=AccountBaiduappRead)
def create_baiduapp(
    *,
    db: Session = Depends(deps.get_db),
    baiduapp_in: AccountBaiduappCreate,
):
    """
    创建百度小程序账号
    """
    baiduapp = account_baiduapp.create(db=db, obj_in=baiduapp_in)
    return baiduapp

@account_router.get("/baiduapp/{acid}", response_model=AccountBaiduappRead)
def read_baiduapp(
    *,
    db: Session = Depends(deps.get_db),
    acid: int,
):
    """
    获取百度小程序账号信息
    """
    baiduapp = account_baiduapp.get(db=db, acid=acid)
    if not baiduapp:
        raise HTTPException(
            status_code=404,
            detail="Baidu app not found"
        )
    return baiduapp

@account_router.put("/baiduapp/{acid}", response_model=AccountBaiduappRead)
def update_baiduapp(
    *,
    db: Session = Depends(deps.get_db),
    acid: int,
    baiduapp_in: AccountBaiduappUpdate,
):
    """
    更新百度小程序账号信息
    """
    baiduapp = account_baiduapp.get(db=db, acid=acid)
    if not baiduapp:
        raise HTTPException(
            status_code=404,
            detail="Baidu app not found"
        )
    baiduapp = account_baiduapp.update(
        db=db,
        db_obj=baiduapp,
        obj_in=baiduapp_in
    )
    return baiduapp

@account_router.delete("/baiduapp/{acid}", response_model=AccountBaiduappRead)
def delete_baiduapp(
    *,
    db: Session = Depends(deps.get_db),
    acid: int,
):
    """
    删除百度小程序账号
    """
    baiduapp = account_baiduapp.get(db=db, acid=acid)
    if not baiduapp:
        raise HTTPException(
            status_code=404,
            detail="Baidu app not found"
        )
    baiduapp = account_baiduapp.delete(db=db, acid=acid)
    return baiduapp 